package com.malty.mall.controller.pms;

import com.malty.mall.common.CommonResult;
import com.malty.mall.domain.dto.req.UpdateStatusReq;
import com.malty.mall.domain.dto.req.pms.PmsProductCateParam;
import com.malty.mall.service.pms.IPmsProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author malty
 */
@RestController
@Api(tags = "商品分类管理")
@RequestMapping("/product/category")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PmsProductCategoryController {
    private final IPmsProductCategoryService productCategoryService;

    @PostMapping("/create")
    @ApiOperation("创建商品分类")
    public CommonResult<Boolean> create(@RequestBody @Validated PmsProductCateParam cateParam) {
        return CommonResult.success(productCategoryService.create(cateParam));
    }

    @PostMapping("/update")
    @ApiOperation("编辑商品分类")
    public CommonResult<Boolean> update(@RequestBody @Validated PmsProductCateParam cateParam) {
        return CommonResult.success(productCategoryService.updateCategoryById(cateParam));
    }

    @ApiOperation("修改商品分类显示状态")
    @PostMapping("/update/show_status")
    public CommonResult<Boolean> updateShowStatus(@RequestBody @Validated UpdateStatusReq statusReq) {
        return CommonResult.success(productCategoryService.updateShowStatus(statusReq));
    }

    @PostMapping("/update/nav_status")
    @ApiOperation("修改商品分类导航栏显示状态")
    public CommonResult<Boolean> updateNavStatus(@RequestBody @Validated UpdateStatusReq statusReq) {
        return CommonResult.success(productCategoryService.updateNavStatus(statusReq));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询商品分类")
    public CommonResult<PmsProductCateParam> queryById(@PathVariable Integer id) {
        return CommonResult.success(productCategoryService.queryCateById(id));
    }

    @GetMapping("/list/{id}")
    @ApiOperation("查询商品分类")
    public CommonResult<List<PmsProductCateParam>> listById(@PathVariable Integer id) {
        return CommonResult.success(productCategoryService.listById(id));
    }

    @GetMapping("/list_all")
    @ApiOperation("查询所有商品分类")
    public CommonResult<List<PmsProductCateParam>> listAll() {
        return CommonResult.success(productCategoryService.listAll());
    }

    @ApiOperation("删除商品分类")
    @GetMapping("/delete/{id}")
    public CommonResult<Boolean> queryById(@PathVariable Long id) {
        return CommonResult.success(productCategoryService.deleteById(id));
    }
}
